<!--{template lyear:header_simple_start}-->
<link href="{MOD_PATH}/images/market.css?{VERHASH}" rel="stylesheet" media="all">
<style>
.card-market .upgrade_progess{
	position: absolute;
	bottom:0;
	left: 0;
	width:0%;
	height: 10%;
}
.list-chose li{margin-bottom:10px;margin-top:10px}
.list-chose li:last-child{margin-bottom:0px}
.list-chose li span.title{font-weight:700}
.list-chose li a{color:#4d5259;margin:0px 5px;padding:3px 5px;white-space:nowrap;border-radius:15px}
.list-chose li a:hover,.list-chose li a.active{background-color:#4c89fb;color:#fff}
.multi-chosen .mdi-close{display:none}
.multi-chosen a.active .mdi-close{display:inherit}
.list-chose li.positions{position:relative;height:30px;overflow:hidden}
.list-chose li a.more{position:absolute;cursor:pointer;padding:0px;top:0px;right:0px}
.list-chose li a.more:after{font-family:"Material Design Icons";content:"\f35d";font-size:18px;-webkit-transition:-webkit-transform 0.25s linear;transition:-webkit-transform 0.25s linear;transition:transform 0.25s linear;transition:transform 0.25s linear,-webkit-transform 0.25s linear}
.list-chose li.positions.on{height:auto}
.list-chose li.positions.on a.more:after{-webkit-transform:rotate(180deg);transform:rotate(180deg)}
.list-chose li a.more:hover{color:#4d5259;background-color:transparent}
</style>
<!--{template lyear:header_simple_end}-->
<main class="bs-main-container">
	<div class="container-fluid">
	  <div class="card">
		<header class="card-header flex-container">
			<a href="{MOD_URL}" class="dcolor">{lang total}<span class="num">$total</span>{lang ge}{lang app}</a>
		</header>
		<div class="card-body">
			<div class="alert alert-warning" role="alert">
				{lang manual_install_tip}
			</div>
			<ul class="list-unstyled list-chose">
				<li class="multi-chosen">
					<span class="title">应用价格：</span>
					<a href="javascript:;" data-search-name="price" data-search-id="-1" class="active">不限</a>
					<a href="javascript:;" data-search-name="price" data-search-id="1">收费</a>
					<a href="javascript:;" data-search-name="price" data-search-id="2">免费</a>
				</li>
				<li class="multi-chosen">
					<span class="title">网络类别：</span>
					<a href="javascript:;" data-search-name="nettype" data-search-id="-1" class="active">不限</a>
					<a href="javascript:;" data-search-name="nettype" data-search-id="1">内网</a>
					<a href="javascript:;" data-search-name="nettype" data-search-id="2">外网</a>
				</li>
				<li class="multi-chosen">
					<span class="title">应用排序：</span>
					<a href="javascript:;" data-search-name="order" data-search-id="-1" class="active">默认</a>
					<a href="javascript:;" data-search-name="order" data-search-id="updatetime">更新时间</a>
					<a href="javascript:;" data-search-name="order" data-search-id="dateline">发布时间</a>
					<a href="javascript:;" data-search-name="order" data-search-id="downloads">下载量</a>
					<a href="javascript:;" data-search-name="order" data-search-id="views">访问量</a>
				</li>
			</ul>
		<!--{if $list}-->
		<div class="d-flex flex-wrap mb-3 justify-content-center">
			<!--{loop $list $value}-->
			<div class="card card-market m-2" style="width:18rem;">
				<div class="card-image color-block-{$value[cover_color]}">
					<div id="progess_{$value[mid]}">
						<div class="progress-bar upgrade_progess" role="progressbar" id="upgrade_progess_{$value[mid]}"></div>
						</div>
					<a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" class="view-detail" title="$value[name]"><img src="$value[coverimg]" alt="$value[name]" /></a>
				</div>
				<div class="card-body">
					<h5 class="card-title"><a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" target="_blank" class="dcolor view-detail text-truncate" title="$value[name]">$value[name]</a><span class="badge rounded-pill bg-success" title="最新版本：$value[version]">V&nbsp;$value[version]</span></h5>
					<p class="card-text text-truncate">{eval echo $value['desc_short']?$value['desc_short']:lang('none');}</p>
				</div>
				<ul class="list-group list-group-flush">
					<li class="list-group-item"><i class="mdi mdi-tag"></i> 应用分类：{$value['classid_name']}</li>
					<!--{if $_GET[order] == 'updatetime'}-->
					<li class="list-group-item"><i class="mdi mdi-update"></i> 更新时间：<!--{eval echo dgmdate($value['updatetime'], 'u');}--></li>
					<!--{elseif $_GET[order] == 'dateline'}-->
					<li class="list-group-item"><i class="mdi mdi-update"></i> 上线时间：$value['dateline']</li>
					<!--{/if}-->
					<li class="list-group-item"><i class="mdi mdi-package-down"></i> {lang big_small}：{eval echo formatsize($value['packagesize']);}</li>
				</ul>
				<div class="card-footer">
					<div class="card-meta">
						<span title="访问量"><i class="mdi mdi-eye"></i>&nbsp;$value[views]</span>
						<span class="mdi mdi-power-on" title="下载量"><i class="mdi mdi-download"></i>&nbsp;$value[downloads]</span>
						<span class="mdi mdi-power-on" title="开发者"><i class="mdi mdi-account"></i>&nbsp;$value[vendor]</span>
						
					</div>
				</div>
				<div class="card-body d-grid">
					<!--{if $value[price]>0}-->
					<button class="btn btn-round btn-danger btn-sm"  onclick="showBuyInfo(this,'$value[mid]')" data-href="$cloudurl?mod=dzzmarket&op=ajax&do=getBuyInfo&mid=$value[mid]" title="{lang buy_contract}">{lang buy}</button>
					<!--{else}-->
						<!--{if $value[package]}--> 
							<!--{if $value["local_appinfo"]}-->
							<button class="btn btn-round btn-secondary btn-sm" disabled data-mid="$value['mid']" title="{lang installed}">
							{lang installed}
							</button>
							<!--{else}-->
							<button class="btn btn-round btn-primary btn-sm" style="white-space: inherit;" onclick="start_check_install('{MOD_URL}&op=install_app_ajax&operation=check_install&appid=$value[identifier]','{$value[mid]}','{$value[baseinfo]}');" id="upgrade_info_{$value[mid]}">{lang install_onekey}</button>
							<!--{/if}--> 
						<!--{else}--> 
						<a class="btn btn-round btn-primary btn-sm view-detail" title="$value[name]" href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]" >{lang view_detail}</a> 
						<!--{/if}-->
					<!--{/if}-->
					<a href="javascript:;" data-href="{$cloudurl}?mod=dzzmarket&op=ajax&do=view&mid=$value[mid]&refer=$refer" class="view-detail btn btn-link" title="$value[name]">{lang examine_details}</a>
				</div>
			</div>
			<!--{/loop}-->
		</div>
		<!--{elseif $error}-->
		<div class="alert alert-danger">$error</div>
		<!--{else}-->
		<div class="text-center">
			<img src="static/image/common/no_list.png" /><br>
			<span class="lead">抱歉，没有找到相关应用</span>
		</div>
		<!--{/if}-->
		<!--{if $multi}-->
		$multi
		<!--{/if}-->
		</div>
	</div>
</div>
</main>
<div class="modal fade">
  <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
    <div class="modal-content">
		<div class="modal-header">
			<h4 class="modal-title text-truncate" id="return_create_newdir"></h4>
			<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
		</div>
      <div class="modal-body"> </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal" aria-label="Close">{lang close}</button>
      </div>
    </div>
    <!-- /.modal-content --> 
  </div>
  <!-- /.modal-dialog --> 
</div>
<!-- /.modal -->
<script type="text/javascript">
	jQuery(document).ready(function(e) {
		$(document).on('click', 'li.positions .more', function() {
			$(this).parent('li').toggleClass('on');
		});
		var queryConfig = new Array();
		var host      = window.location.host;
		var pathname  = window.location.pathname;
		var protocol  = document.location.protocol;
		var queryStr  = location.search.substr(1);
		queryStr = queryStr.split('&');
		for (let i = 0; i < queryStr.length; i++) {
			let q = queryStr[i].split('=')
			if (q.length === 2) {
				queryConfig[q[0]] = q[1];
			}
			$('li.multi-chosen a').each(function() {
				if ($(this).data('search-name') == q[0] && $(this).data('search-id') == q[1]) {
					$(this).addClass('active').siblings().removeClass('active');
				}
			});
		}
	
		$(document).on('click', 'li a i.mdi-close', function() {
			var name = $(this).parent('a').data('search-name');
			delete queryConfig[name];
			var urlStr = assemblyURL(queryConfig);
			window.location.href = urlStr;
		});
		
		$(document).on('click', 'li.multi-chosen a:not(.more)', function(ev) {
			if(ev.target!=this) return false;
			var name = $(this).data('search-name');
			var id = $(this).data('search-id');
			queryConfig[name] = id;
			var urlStr = assemblyURL(queryConfig);
			window.location.href = urlStr;
		});
		
		// 组装url地址
		function assemblyURL(queryConfig) {
			var _str = "";
			for(var o in queryConfig){
				if(queryConfig[o] != -1 && o !== 'page'){ // 排除 page 参数
					_str += o + "=" + queryConfig[o] + "&";
				}
			}
			var query_str = _str.substring(0, _str.length-1);
			
			return protocol + '//' + host + pathname + '?' + query_str;
		}
	});
	jQuery('.view-detail').on('click',function(){
		showBuyInfo(this,'modal-lg');
		return false;
	});
	var ajaxurl='{$cloudurl}';
	function showBuyInfo(obj,size){
		var url=jQuery(obj).data('href');
		var title=jQuery(obj).attr('title');
		if(size){
			jQuery('.modal .modal-dialog').addClass(size);
		}
		jQuery.get(url,function(html){
			html=html.replace(/src=\"index\.php/ig,'src="$cloudurl');
			jQuery('.modal .modal-body').html(html);
		});
		jQuery('.modal .modal-title').html(title);
		jQuery('.modal').modal('show');
	}
	function getNext(url){
		jQuery.get(url,function(html){
			var li=jQuery('.appitem-next');
			li.replaceWith(html);
		});
	}

	function start_check_install(url,mid,data){ 
		jQuery.ajax({
				type:'post',
				async: true, 
				url:url,
				data:{"baseinfo":data },
				success:function(json){
						//jQuery('#install_button_'+mid).html("&nbsp;");  
						if(json.status==0){
							jQuery('#upgrade_info_'+mid).show().addClass("btn-warning").html(json.msg); 
						}else if(json.status==1){ 
							jQuery('#upgrade_info_'+mid).show().text(json.msg);
							jQuery('#upgrade_progess_'+mid).show().animate({width:json.percent+"%"},json.second,function(){
								startinstsallapp(json.url,mid,data);
							});
						}else{
							window.location.reload();
						}
				},
				error: function(xhr, status, error) {
					showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
				}
		});
	}

	function startinstsallapp(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						startgetinstallcrossorpatchfile(json.url,mid,data);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startgetinstallcrossorpatchfile(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						if(json.step==2){
							startgetinstallcrossorpatchfile(json.url,mid,data);
						}else{ 
							startinstallfile(json.url,mid,data);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startinstallfile(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						 if(json.step!=5){
							startinstallfile(json.url,mid,data);
						}else{ 
							installover(json.url,mid,data);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function installover(url,mid,data){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{"baseinfo":data},
			success:function(json){ 
				if(json.status==0){ 
					jQuery('#upgrade_info_'+mid).addClass("btn-warning").html(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).css("width","100%");
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function start_check_upgrade(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				jQuery('#upgrade_button_'+mid).html("&nbsp;");  
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).show().text(json.msg);  
				}else{ 
					jQuery('#upgrade_info_'+mid).show().text(json.msg);
					jQuery('#upgrade_progess_'+mid).show().animate({width:json.percent+"%"},json.second,function(){
					startupgrade(json.url,mid);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startupgrade(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){ 
				if(json.status==0){
					jQuery('#upgrade_info_'+mid).text(json.msg); 
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						startgetcrossorpatchfile(json.url,mid);
					});
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startgetcrossorpatchfile(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						if(json.step==2){
							startgetcrossorpatchfile(json.url,mid);
						}else{
							startupgradefile(json.url,mid);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function startupgradefile(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){ 
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_info_'+mid).text(json.msg);
					jQuery('#upgrade_progess_'+mid).animate({width:json.percent+"%"},json.second,function(){
						 if(json.step!=5){
							startupgradefile(json.url,mid);
						}else{
							upgradeover(json.url,mid);
						}
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	}

	function upgradeover(url,mid){
		jQuery.ajax({
			type:'post',
			async: true, 
			url:url,
			data:{},
			success:function(json){
				if(json.status==0){ 
					alert( json.msg);
				}else{
					jQuery('#upgrade_progess_'+mid).animate({width:"100%"},300,function(){
						jQuery('#upgrade_progess_'+mid).hide().css("width","0");
						start_check_upgrade(json.url,mid);
					}); 
				}
			},
			error: function(xhr, status, error) {
				showmessage('Request failed:' + status +' ' +error, 'error', 3000, 1);
			}
		});
	} 
		
</script> 
<!--{template lyear:footer_simple}-->